import {createStore} from 'vuex'
import menusStore from "@/store/modules/menus";

// 创建一个新的 store 实例
const store = createStore({
    state() {
        const editableTabsValue = window.localStorage.getItem("editableTabsValue") || 'profile';
        const editableTabs = JSON.parse(window.localStorage.getItem("editableTabs")) || [{
            title: '主页',
            name: 'profile',
            content: '',
        }];
        return {
            token: null,
            editableTabsValue: editableTabsValue,
            editableTabs: editableTabs
        }
    },
    mutations: {
        setToken(state, token) {
            state.token = token
        },
        clearToken(state) {
            state.token = null
        },
        setEditableTabsValue(state, val){
            state.editableTabsValue = val
            window.localStorage.setItem("editableTabsValue", val);
        },
        setEditableTabs(state, val){
            state.editableTabs = val
            window.localStorage.setItem("editableTabs", JSON.stringify(val));
        }
    },
    getters: {},
    modules: {
        menusStore
    }
})

// 将 store 实例作为插件安装
export default store
